using System.Collections.Generic;
using System.Text.Json.Serialization; 

namespace JMClient.Assets.ClientDesignConfig;

public class DesignConfig
{

/// <summary>
/// 窗口主配置类，包含所有窗口相关的设置
/// </summary>
public sealed class WindowConfig
{
    /// <summary>
    /// 默认窗口宽度
    /// </summary>
    [JsonPropertyName("DefaultWidth")]
    public double DefaultWidth { get; set; } = 1200;

    /// <summary>
    /// 默认窗口高度
    /// </summary>
    [JsonPropertyName("DefaultHeight")]
    public double DefaultHeight { get; set; } = 800;

    /// <summary>
    /// 窗口启动位置
    /// </summary>
    [JsonPropertyName("StartupPosition")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WindowPosition StartupPosition { get; set; } = WindowPosition.CenterScreen;

    /// <summary>
    /// 窗口是否可调整大小
    /// </summary>
    [JsonPropertyName("IsResizable")]
    public bool IsResizable { get; set; } = true;

    /// <summary>
    /// 上次窗口关闭时的位置（用于WindowPosition.Manual模式）
    /// </summary>
    [JsonPropertyName("lastWindowPosition")]
    public PointPosition? LastWindowPosition { get; set; }

    /// <summary>
    /// 颜色配置
    /// </summary>
    [JsonPropertyName("Colors")]
    public ColorPalette Colors { get; set; } = new ColorPalette();

    /// <summary>
    /// 布局模板字典（Key: 布局名称，Value: 布局配置）
    /// </summary>
    [JsonPropertyName("LayoutTemplates")]
    public Dictionary<string, LayoutTemplate> LayoutTemplates { get; set; } = new Dictionary<string, LayoutTemplate>();

    /// <summary>
    /// 配置版本（用于未来迁移）
    /// </summary>
    [JsonPropertyName("ConfigVersion")]
    public int ConfigVersion { get; set; } = 1;
}
/// <summary>
/// 颜色调色板配置
/// </summary>
public sealed class ColorPalette
{
    /// <summary>
    /// 基础主题模式（Light/Dark/Auto）
    /// </summary>
    [JsonPropertyName("baseTheme")]
    public string BaseTheme { get; set; } = "Light";

    /// <summary>
    /// 主色（Primary Color）
    /// </summary>
    [JsonPropertyName("primary")]
    public string Primary { get; set; } = "#6200EE";

    /// <summary>
    /// 辅助色（Secondary Color）
    /// </summary>
    [JsonPropertyName("secondary")]
    public string Secondary { get; set; } = "#03DAC6";

    /// <summary>
    /// 背景色（Background Color）
    /// </summary>
    [JsonPropertyName("background")]
    public string Background { get; set; } = "#FFFFFF";

    /// <summary>
    /// 表面色（Surface Color）
    /// </summary>
    [JsonPropertyName("surface")]
    public string Surface { get; set; } = "#FAFAFA";

    /// <summary>
    /// 错误色（Error Color）
    /// </summary>
    [JsonPropertyName("error")]
    public string Error { get; set; } = "#B00020";

    /// <summary>
    /// 主色上的文本颜色（Text Color on Primary）
    /// </summary>
    [JsonPropertyName("onPrimary")]
    public string OnPrimary { get; set; } = "#FFFFFF";

    /// <summary>
    /// 辅助色上的文本颜色（Text Color on Secondary）
    /// </summary>
    [JsonPropertyName("onSecondary")]
    public string OnSecondary { get; set; } = "#000000";

    /// <summary>
    /// 是否启用主题动画
    /// </summary>
    [JsonPropertyName("enableThemeTransitions")]
    public bool EnableThemeTransitions { get; set; } = true;
}
/// <summary>
/// 布局模板配置
/// </summary>
public sealed class LayoutTemplate
{
    /// <summary>
    /// 列定义列表
    /// </summary>
    [JsonPropertyName("columns")]
    public List<GridDefinition> Columns { get; set; } = new List<GridDefinition>();

    /// <summary>
    /// 行定义列表
    /// </summary>
    [JsonPropertyName("rows")]
    public List<GridDefinition> Rows { get; set; } = new List<GridDefinition>();

    /// <summary>
    /// 区域映射列表
    /// </summary>
    [JsonPropertyName("regions")]
    public List<RegionMapping> Regions { get; set; } = new List<RegionMapping>();

    /// <summary>
    /// 布局描述（可选）
    /// </summary>
    [JsonPropertyName("description")]
    public string Description { get; set; } = string.Empty;
}
/// <summary>
/// 网格定义（用于行和列）
/// </summary>
public sealed class GridDefinition
{
    /// <summary>
    /// 网格单位类型（Auto/Pixel/Star）
    /// </summary>
    [JsonPropertyName("type")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public GridUnitType Type { get; set; } = GridUnitType.Star;

    /// <summary>
    /// 网格值（对于Star类型表示比例，对于Pixel类型表示像素值）
    /// </summary>
    [JsonPropertyName("value")]
    public double Value { get; set; } = 1;

    /// <summary>
    /// 最小尺寸约束（可选）
    /// </summary>
    [JsonPropertyName("minSize")]
    public double? MinSize { get; set; }

    /// <summary>
    /// 最大尺寸约束（可选）
    /// </summary>
    [JsonPropertyName("maxSize")]
    public double? MaxSize { get; set; }
}
/// <summary>
/// 区域映射配置
/// </summary>
public sealed class RegionMapping
{
    /// <summary>
    /// 区域名称（必须匹配Prism区域名称）
    /// </summary>
    [JsonPropertyName("regionName")]
    public string RegionName { get; set; } = string.Empty;

    /// <summary>
    /// 所在列索引（从0开始）
    /// </summary>
    [JsonPropertyName("column")]
    public int Column { get; set; } = 0;

    /// <summary>
    /// 所在行索引（从0开始）
    /// </summary>
    [JsonPropertyName("row")]
    public int Row { get; set; } = 0;

    /// <summary>
    /// 列跨越数（默认1）
    /// </summary>
    [JsonPropertyName("columnSpan")]
    public int ColumnSpan { get; set; } = 1;

    /// <summary>
    /// 行跨越数（默认1）
    /// </summary>
    [JsonPropertyName("rowSpan")]
    public int RowSpan { get; set; } = 1;

    /// <summary>
    /// 水平对齐方式（可选）
    /// </summary>
    [JsonPropertyName("horizontalAlignment")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public HorizontalAlignment? HorizontalAlignment { get; set; }

    /// <summary>
    /// 垂直对齐方式（可选）
    /// </summary>
    [JsonPropertyName("verticalAlignment")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public VerticalAlignment? VerticalAlignment { get; set; }
}
/// <summary>
/// 点位置信息（用于保存窗口位置）
/// </summary>
public sealed class PointPosition
{
    /// <summary>
    /// X坐标
    /// </summary>
    [JsonPropertyName("x")]
    public int X { get; set; }

    /// <summary>
    /// Y坐标
    /// </summary>
    [JsonPropertyName("y")]
    public int Y { get; set; }
}
/// <summary>
/// 窗口启动位置枚举
/// </summary>
public enum WindowPosition
{
    /// <summary>
    /// 屏幕居中
    /// </summary>
    CenterScreen,
    
    /// <summary>
    /// 手动指定位置（使用LastWindowPosition）
    /// </summary>
    Manual,
    
    /// <summary>
    /// 最大化启动
    /// </summary>
    Maximized,
    
    /// <summary>
    /// 最小化启动（不常用）
    /// </summary>
    Minimized
}
/// <summary>
/// 网格单位类型枚举
/// </summary>
public enum GridUnitType
{
    /// <summary>
    /// 自动大小（根据内容自适应）
    /// </summary>
    Auto,
    
    /// <summary>
    /// 固定像素大小
    /// </summary>
    Pixel,
    
    /// <summary>
    /// 比例分配大小
    /// </summary>
    Star
}
/// <summary>
/// 水平对齐方式枚举
/// </summary>
public enum HorizontalAlignment
{
    Left,
    Center,
    Right,
    Stretch
}
/// <summary>
/// 垂直对齐方式枚举
/// </summary>
public enum VerticalAlignment
{
    Top,
    Center,
    Bottom,
    Stretch
}
}